#ifndef MUSICPLAYER_H
#define MUSICPLAYER_H

#include <QWidget>
#include "head.h"
#include "musicform1.h"
#include "ui_musicform1.h"

#include "musicform2.h"
#include "ui_musicform2.h"

#include "musicform3.h"
#include "ui_musicform3.h"

#include "musiclyric.h"
#include "ui_musiclyric.h"

#include "customdelegete.h"
#include "databaseop.h"
namespace Ui {
class MusicPlayer;
}


struct song
{
    QString songname;   //歌曲名
    QString singer;     //歌手
    QString album_name; //专辑
    int duration2;      //时间
    int music_id;       //音乐id
};

class MusicPlayer : public QWidget
{
    Q_OBJECT

public:


    explicit MusicPlayer(QWidget *parent = nullptr);
    ~MusicPlayer();

    void parseJson(QByteArray byteArray);


    void updateRecentPlayTable();//最近播放
    void showRecentPlays();
    void parseLyrics(const QByteArray &jsonData);


public slots:


    void replyFinished(QNetworkReply *reply);

    void on_buttonLyricsReceived(QNetworkReply *reply);
private slots:
    void on_horizontalSlider_sliderReleased();

    void on_buttonPrevious_clicked();

    void on_buttonPause_clicked();

    void on_buttonNext_clicked();

    void on_buttonSearch_clicked();

    void on_listWidget_Music_currentRowChanged(int currentRow);

    void on_tableView_clicked(const QModelIndex &index);

    void on_tableView_doubleClicked(const QModelIndex &index);

    void positionChangedSlot(qint64 position); //播放位置发生改变的槽函数

    void durationChangedSlot(qint64 duration);//播放总时长


private:
    Ui::MusicPlayer *ui;

    QNetworkAccessManager *manager;
    QStandardItemModel *pModel;

    QList <int> misicIdList;    //存放音乐的id号
    QMediaPlaylist *playlist; //媒体播放器列表
    QMediaPlayer *player ;


    MusicForm1 *musicF1;
    MusicForm2 *musicF2;
    MusicForm3 *musicF3;
    MusicLyric *musicLy;//四个窗体


    QList<song> song_List;

    QStringList titles; //标题头

    databaseOP *dDatabase;

    unsigned int id = -1;
    QString songName;
    QString albumName;
    QString singerName;
    QString myFavorite="未收藏";
    float duration = -1;

    QList<QPair<QString, QString>> recentPlayList; // 存储最近播放的歌曲（<歌名, 歌手>）


    QMap<int,QString> lrcMap;


};

#endif // MUSICPLAYER_H
